package com.molichuxing.services.infrastructure.service.impl;

import com.alibaba.fastjson.JSON;
import com.molichuxing.framework.dto.Paged;
import com.molichuxing.services.infrastructure.bean.OperationLogBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.OperationLogMapper;
import com.molichuxing.services.infrastructure.dto.response.request.create.OperationLogCreateDto;
import com.molichuxing.services.infrastructure.dto.response.response.OperationLogDto;
import com.molichuxing.services.infrastructure.service.OperationLogService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 系统操作日志表 服务实现类
 * @author xuelin yi
 * @since 2019-09-20
 */
@Service("operationLogService")
public class OperationLogServiceImpl implements OperationLogService {

    private static final Logger log = Logger.getLogger(OperationLogServiceImpl.class);

    @Resource
    private OperationLogMapper operationLogMapper;

    @Override
    public Boolean createOperationLog(OperationLogCreateDto createDto) throws Exception {
        int result = operationLogMapper.createOperationLog(Convert.toOperationLogBean(createDto));
        if(result > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Paged<OperationLogDto> getOperationLogByDealerId(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        int count = operationLogMapper.getOperationLogCount(map);
        if(count <= 0) {
            return new Paged<>();
        }
        List<OperationLogBean> pageResult = operationLogMapper.getOperationLogByDealerId(map, pageNum, pageSize);
        log.info("根据条件查询操作列表 出参：pageResult： "+ JSON.toJSONString(pageResult));
        return new Paged<>(Convert.toOperationLogDto(pageResult), count, pageSize );
    }
    
    
    /**
     * 获取操作日志记录
     * @param map
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Paged<OperationLogDto> getOperationLogPage(Map<String, Object> map, Integer pageNum, Integer pageSize) {
    	 int count = operationLogMapper.getOperationLogPageCount(map);
         if(count <= 0) {
             return new Paged<>();
         }
         List<OperationLogBean> pageResult = operationLogMapper.getgetOperationLogPage(map, pageNum, pageSize);
         log.info("根据条件查询操作列表 出参：pageResult： "+ JSON.toJSONString(pageResult));
         return new Paged<>(Convert.toOperationLogDto(pageResult), count, pageSize );
    }
}


